
[dbo].[sp_asi_GetCounter2]
CREATE PROCEDURE sp_asi_GetCounter2 @CounterName varchar(30), @CounterValue int out
AS
if not exists (select COUNTER_NAME from Counter where COUNTER_NAME=@CounterName)
insert Counter (COUNTER_NAME, LAST_VALUE) values (@CounterName,0)
update Counter
set LAST_VALUE=LAST_VALUE + 1, LAST_UPDATED=getdate(),
UPDATED_BY=user_name()
where COUNTER_NAME= @CounterName
select @CounterValue = LAST_VALUE from Counter where COUNTER_NAME= @CounterName
GO
GRANT EXECUTE ON [dbo].[sp_asi_GetCounter2] TO [IMIS]
GO